package com.mingyuan.library.domain.lending.patron.model.valueobject;

import com.mingyuan.library.domain.common.model.ValueObject;
import com.mingyuan.library.domain.lending.book.model.valueobject.BookId;
import com.mingyuan.library.domain.lending.librarybranch.model.valueobject.LibraryBranchId;
import lombok.NonNull;
import lombok.Value;

import java.util.Map;
import java.util.Set;

import static java.util.Collections.emptySet;

/**
 * 逾期借阅
 * @author yangzk
 * @date 2023/12/28 19:13
 **/
@Value
@ValueObject
public class OverdueCheckouts {
    /**
     * 最大逾期资源数量(最多可逾期几本图书)
     */
    public static int MAX_COUNT_OF_OVERDUE_RESOURCES = 2;
    /**
     * 逾期借阅列表 key: 图书馆分馆ID value: 图书集合
     */
    @NonNull Map<LibraryBranchId, Set<BookId>> overdueCheckouts;
    /**
     * 获取指定图书馆分馆逾期借阅数量
     * @author yangzk
     * @param libraryBranchId 图书馆分馆ID
     * @date 2023/12/28 19:15
     * @return 该图书馆分馆逾期图书数量
     **/
   public int countAt(@NonNull LibraryBranchId libraryBranchId) {
        return overdueCheckouts.getOrDefault(libraryBranchId, emptySet()).size();
    }

}



